import { prepareWrite } from '../../../bin/frameworks/filesystem/prepareWrite';

import {
  getFileDataOperationToken,
  getFileDataOperationInvalidNoTemplatesForCss,
  getFileDataOperationInvalidNoTemplatesForStory,
  getFileDataOperationInvalidNoTemplatesForComponent
} from '../../../testdata/getFileDataOperation';

describe('Failure cases', () => {
  test('It should throw an error if no argument is provided', () => {
    // @ts-ignore
    expect(() => prepareWrite()).toThrowError();
  });

  test('It should throw an error if type is "css" but data is missing templates', () => {
    // @ts-ignore
    expect(() => prepareWrite(getFileDataOperationInvalidNoTemplatesForCss)).toThrowError();
  });

  test('It should throw an error if type is "story" but data is missing templates', () => {
    // @ts-ignore
    expect(() => prepareWrite(getFileDataOperationInvalidNoTemplatesForStory)).toThrowError();
  });

  test('It should throw an error if type is "component" but data is missing templates', () => {
    expect(
      // @ts-ignore
      () => prepareWrite(getFileDataOperationInvalidNoTemplatesForComponent)
    ).toThrowError();
  });
});

describe('Success cases', () => {
  test('It should prepare a file to be written to disk', () => {
    // @ts-ignore
    expect(prepareWrite(getFileDataOperationToken)).toMatchObject({
      fileContent: `// THIS FILE IS AUTO-GENERATED BY FIGMAGIC. DO NOT MAKE EDITS IN THIS FILE! CHANGES WILL GET OVER-WRITTEN BY ANY FURTHER PROCESSING.

const colors = {
 \"green3\": \"rgba(111, 207, 151, 1)\",
 \"green2\": \"rgba(39, 174, 96, 1)\",
 \"green1\": \"rgba(33, 150, 83, 1)\",
 \"blue3\": \"rgba(86, 204, 242, 1)\",
 \"blue2\": \"rgba(45, 156, 219, 1)\",
 \"blue1\": \"rgba(47, 128, 237, 1)\",
 \"yellow\": \"rgba(242, 201, 76, 1)\",
 \"orange\": \"rgba(242, 153, 74, 1)\",
 \"red\": \"rgba(235, 87, 87, 1)\",
 \"neon\": \"rgba(228, 255, 193, 1)\",
 \"gray5\": \"rgba(242, 242, 242, 1)\",
 \"gray4\": \"rgba(224, 224, 224, 1)\",
 \"gray3\": \"rgba(189, 189, 189, 1)\",
 \"gray2\": \"rgba(130, 130, 130, 1)\",
 \"gray1\": \"rgba(79, 79, 79, 1)\",
 \"white\": \"rgba(255, 255, 255, 1)\",
 \"black\": \"rgba(51, 51, 51, 1)\"
}

export default colors;`,
      filePath: 'tokens/colors.mjs'
    });
  });
});
